package com.huang.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huang.eduservice.client.VodClient;
import com.huang.eduservice.entity.EduVideo;
import com.huang.eduservice.mapper.EduVideoMapper;
import com.huang.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-03-21
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;

    @Override
    public void removeVideoByCourseId(String id) {

        QueryWrapper<EduVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", id);
        List<EduVideo> eduVideos = baseMapper.selectList(wrapper);
        ArrayList<String> list = new ArrayList<>();
        for (EduVideo video : eduVideos) {
            list.add(video.getVideoSourceId());
        }
        if (list.size() > 0) {
            vodClient.deleteVedioList(list);  //删除视频  下面再删除小节
        }


        QueryWrapper<EduVideo> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("course_id", id);
        baseMapper.delete(wrapper1);
    }
}
